package drt.toolbox.screen;

import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;

import org.w3c.dom.css.RGBColor;

/**
 * @author Juan Horno
 * 
 * Objeto que representa un pixel de la pantalla, este tiene unas coordenadas y un color
 *
 */
public class Pixel {
	public int x;
	public int y;
	private int color;

	public Pixel() {
		this.x = 0;
		this.y = 0;
		color = 0;
	}

	public Pixel(int x, int y) {
		this.x = x;
		this.y = y;
		color = 0;
	}

	public Pixel(String color) {
		x = 0;
		y = 0;
		this.color = Integer.parseInt(color.replace("#", ""), 16) + 0xFF000000;
	}

	public Pixel(int x, int y, int color) {
		this.x = x;
		this.y = y;
		this.color = color;
	}
	
	public Pixel(int x, int y, String color) {
		this.x = x;
		this.y = y;
		this.color = Integer.parseInt(color.replace("#", ""), 16) + 0xFF000000;
	}

	public Pixel(int x, int y, BufferedImage image) {
		this.x = x;
		this.y = y;
		if (x < 0 || y < 0 || x >= image.getWidth() || y >= image.getHeight()) {
			System.out.println("Pixel not found (out of range)");
			color = 0;
		} else {
			color = image.getRGB(x, y);
		}
	}

	public int getColor() {
		return color;
	}

	@Override
	public boolean equals(Object obj) {
		Pixel other = (Pixel) obj;
		if (getColor() == other.getColor()) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("P[" + x + "," + y + ","
				+ String.format("#%06X", (0xFFFFFF & color)) + "]");
		return sb.toString();
	}

}
